﻿// 7-17 名人堂与代金券 (25 分).cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 7-16 月饼 (25 分)

//user:lidongcheng
//level:6
//date:20191108
//key:注意最后对输出的控制，要先模拟一次输出得知总输出次数
//才能控制换行符
//2：代金卷控制，有两个测试点是没有g到100的成绩的，都是g到60的.

#include <iostream>
#include<algorithm>
using namespace std;
void swap(int* a, string* b, int i) {
	int a1;
	string b1;
	a1 = a[i];
	a[i] = a[i + 1];
	a[i + 1] = a1;

	b1 = b[i];
	b[i] = b[i + 1];
	b[i + 1] = b1;
}
void bsort(int* a, string* b, int n) {//a这里是传值引用，就是会对a内值做修改
	int i;
	int j;

	n--;//因为在main函数里这个n对于数组来说是多一个的。
	for (j = 0; j < n; j++)
	{
		for (i = 0; i < n; i++)//冒泡排序，使比值最高那个排最前
		{

			if (a[i] <a[i + 1]||((a[i] == a[i + 1])&&b[i]>b[i+1]))
			{
				swap(a, b, i);
			}
		}
	}
}

int main()
{
	int n, g,k;
	cin >> n >> g>>k;
	int i;
	int* a = new int[n];//存
	string* b = new string[n];//存全部
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
	
		cin >> a[i];
	}

	bsort(a, b, n);//排序函数，按的值重新拍一次
	int money_g_100 = 0;
	int money_60_g = 0;
	int money ;


	int i1=0;//记录g到100的学生个数
	for (i = 0; i < n; i++)
	{
		if (a[i] < g) {//第五次循环i为4，但这确实表面有四个在g之上
			money_g_100=(i)*50;
			i1 = i;
			break;
		}
	
	}

	for (i = 0; i < n; i++)
	{
		if (a[i] < 60) 
		{
			money_60_g = (i - i1) * 20;
			break;

		}
	}
	money = money_60_g + money_g_100;
	cout << money << endl;
	int d = 0; int c = 0;


	for (i = 0; i < k; i++)
	{
		if (a[i] == a[i + 1])
		{

			
			while (a[i] == a[i + 1])
			{
				c++;
				i++;
			}
		
			c++;

		}


		else {
			c++;
		}

	}
 

	int c1=0;
	for (i = 0; i < k; i++)
	{
		if (a[i] == a[i + 1])
		{
			
			d = i;
			while (a[i] == a[i + 1])
			{
				
				cout << d+1 << " ";
				cout << b[i] << " " << a[i];
				
				if (c1 != c-1) {
					cout << "\n";
				}
				c1++;
				i++;
			}
			cout << d + 1 << " ";
			cout << b[i] << " " << a[i];
			
			if (c1 != c-1) {
				cout << "\n";
			}
				c1++;
			
		}
		
		
		else {
			cout << i + 1 << " ";
			cout << b[i] << " " << a[i];
		
			if (c1 != c-1) {
				cout << "\n";
			}
			c1++;
		}

	} 
	
}